# class Cat:
#     def eat(self):
#         print("%s吃"% self.name)
#
#     def drink(self):
#         print("喝")
#
# tom = Cat()
# tom.eat()
# tom.drink()
# toq = Cat()
# toq.eat()
# toq.drink()


# class Cat:
#     def __init__(self):
#         print("初始化")
#         self.name = "tom"
#
#     def eat(self):
#         print("%s爱吃鱼"%self.name)
#
# tom = Cat()
# tom.eat()


# class Cat:
#     def __init__(self,new_name):
#         self.name = new_name
#         print("%s来了"%self.name)
#
#     def __del__(self):
#         print("%s 去了"% self.name)
#
#     def __str__(self):
#         return "我是小猫：%s"% self.name
#
# tom = Cat("Tom")
# print(tom)

# class Cat:
#     def eat(self):
#         self.name = "Tom"
#         print("%s love fish"% self.name)
#
# tom  = Cat()
# tom.eat()

# __del__ 的使用方法
# class Cat:
#
#     def __init__(self, new_name):
#
#         self.name = new_name
#
#         print("%s 来了" % self.name)
#
#     def __del__(self):
#
#         print("%s 去了" % self.name)
#
# # tom 是一个全局变量
# tom = Cat("Tom")
# print(tom.name)
#
# # del 关键字可以删除一个对象
# #del tom
#
# print("-" * 50)


# class Person:
#     def __init__(self,name,weight):
#         self.name = name
#         self.weight = weight
#
#     def __str__(self):
#         return "my name is %s weight %.2f"% (self.name,self.weight)
#
#     def run(self):
#         print("%s run"% self.name)
#         self.weight -= 0.5
#
#     def eat(self):
#         print("%s eat"% self.name)
#         self.weight += 1
#
# Tom = Person("tom",78)
# Tom.run()
# Tom.eat()
#
# print(Tom)
#
# Beauty = Person("brauty",50)
# Beauty.run()
# Beauty.eat()
# print(Beauty)

class HouseItem:
    def __init__(self,name,area):
        self.name = name
        self.area = area
    def __str__(self):
        return "%s占地面积%.2f"%(self.name,self.area)

bed = HouseItem("床",4)
chest = HouseItem("衣柜",3)
table = HouseItem("餐桌",4)

print(bed)
print(chest)
print(table)

class House:
    def __init__(self,house_type,area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []
    def __str__(self):

        return ("户型：%s\n总面积%.2f[剩余：%.2f]\n家具：%s"%(self.house_type,self.area,self.free_area,self.item_list))
    def add_item(self,item):
        print("要添加%s"%item)
        if item.area > self.free_area:
            print("%sde的面积太大，不能添加"%item.name)
            return

        self.item_list.append(item.name)
        self.free_area -= item.area

# 创建房子对象
my_home = House("两室一厅",60)

my_home.add_item(bed)
my_home.add_item(chest)
my_home.add_item(table)

print(my_home)